﻿@{
	ViewData["Title"] = "用户登录";
}
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>用户登录</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
	<link rel="stylesheet" href="~/lib/layuiadmin/layui/css/layui.css" media="all">
	<link rel="stylesheet" href="~/lib/layuiadmin/style/login.css" media="all">
</head>
<body>
	<div class="layadmin-user-login layadmin-user-display-show" style="display: none;">
		<div class="layadmin-user-login-main">
			<div class="layadmin-user-login-box layadmin-user-login-header">
				<h2>通用后台管理系统</h2>
			</div>
			<div class="layadmin-user-login-box layadmin-user-login-body layui-form">
				<div class="layui-form-item">
					<label class="layadmin-user-login-icon layui-icon layui-icon-username" ></label>
					<input type="text" name="username" lay-verify="required" placeholder="用户名" class="layui-input">
				</div>
				<div class="layui-form-item">
					<label class="layadmin-user-login-icon layui-icon layui-icon-password"></label>
					<input type="password" name="password" lay-verify="required" placeholder="密码" class="layui-input">
				</div>
				<div class="layui-form-item">
					<div class="layui-row">
						<div class="layui-col-xs7">
							<label class="layadmin-user-login-icon layui-icon layui-icon-vercode"></label>
							<input type="text" name="vercode" id="login-vercode" lay-verify="required" placeholder="图形验证码" class="layui-input">
						</div>
						<div class="layui-col-xs5">
							<div style="margin-left: 10px;">
								<button type="button" class="layui-btn" id="btncode" style="width:100px; text-align:center;color:black; font-size:24px; background-color:darkgray;"></button>
							</div>
						</div>
					</div>
				</div>
				<div class="layui-form-item" style="margin-bottom: 20px;">
				</div>
				<div class="layui-form-item">
					<button class="layui-btn layui-btn-fluid" lay-submit lay-filter="login">登 入</button>
				</div>
			</div>
		</div>

		<div class="layui-trans layadmin-user-login-footer">
			<p>© 2025 XXX</p>
		</div>
	</div>

	<script src="~/lib/layuiadmin/layui/layui.js"></script>
	<script>
		layui.use(['form', 'layer'], function () {
			var $ = layui.$				
				, form = layui.form;

			form.render();

			$(function () {
				GetCode();
				$("#btncode").click(function () {
					GetCode();
				});
			});
			function GetCode() {
				$.ajax({
					url: "/api/user/getcode",					
					success: function (code) {
						$("#btncode").html(code);
					},
				});
			}

			//提交
			form.on('submit(login)', function (obj) {				
				//请求登入接口
				$.post({
					url: '/api/user/login',
					type: "post",
					data: JSON.stringify(obj.field),					
					contentType: "application/json",
					success: function (res) {
						if (res.code == 200) {
							location.href = res.data;//登录成功
						} else {
							layer.msg(res.msg);
							GetCode();
						}
					}
				});

			});
		});
	</script>
</body>
</html>